<template>
  <div class="auBackground">
    <div class="style">
      <el-form ref="updateform" :model="form" label-width="80px">
        <el-form-item label="平台logo">
          <img
            @click="updateimg()"
            width="250px"
            :src="updateform.factory_logo"
            alt=""
          />
        </el-form-item>
        <el-form-item label="平台icon">
          <img width="250px" :src="updateform.factory_icon" alt="" />
        </el-form-item>
        <el-form-item label="工厂名称">
          <el-input v-model="updateform.factory_name"></el-input>
        </el-form-item>
        <el-form-item label="平台名称">
          <el-input v-model="updateform.platform_name"></el-input>
        </el-form-item>
        <el-form-item label="IP">
          <el-input v-model="updateform.ip"></el-input>
        </el-form-item>
        <el-form-item label="端口">
          <el-input v-model="updateform.port"></el-input>
        </el-form-item>
      </el-form>
      <div class="addbutton">
        <el-button @click="Update(updateform)"
          >提交<i class="el-icon-upload el-icon--right"></i
        ></el-button>
        <el-button @click="Return()"
          >返回<i class="el-icon-s-home"></i
        ></el-button>
      </div>
    </div>
    <el-dialog
      title="更新logo"
      :visible.sync="logodialog"
      :modal-append-to-body="false"
    >
      <el-upload
        class="upload-demo"
        drag
        action="http://62.234.98.16/fileserver/fileserver/upload"
        multiple
        name="factory_logo"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">
          只能上传jpg/png文件，且不超过500kb
        </div>
      </el-upload>
    </el-dialog>
  </div>
</template>

<script>
import { showplatform, updateplatform } from '@/api/platform.js'
export default {
  name: '',

  data () {
    return {
      updateform: {
        factory_name: '',
        platform_name: '',
        ip: '',
        port: '',
        factory_icon: '',
        factory_logo: '',
        panorama: '',
        common_power: '',
        high_power: '',
        ultra_high_power: '',
        toner: ''
      },
      logodialog: false
    }
  },
  created () {
    this.ShowPlatform()
    // 这个界面没用上了
  },
  methods: {
    ShowPlatform () {
      showplatform().then(res => {
        this.updateform = res.data.data[0]
      })
    },
    Return () {
      this.$router.push({
        name: 'platform'
      })
    },
    Update () {
      updateplatform(this.updateform).then(res => {
        this.$message({
          message: '修改成功',
          type: 'success'
        })
        this.$router.push({
          name: 'platform'
        })
      })
    },
    updateimg () {
      this.logodialog = true
    }
  }
}
</script>
<style scoped>
.auBackground {
  background-color: rgb(255, 255, 255);
  width: 100%;
  min-height: calc(100vh - 50px);
  position: relative;
  overflow: hidden;
  box-shadow: -1px 1px 5px #888888;
  margin: 10px;
}
.addbutton {
  margin-left: 15px;
  margin-top: 20px;
}
.style {
  padding: 1%;
}
</style>
